package com.wuercloud.config.db;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * Created by JiangWL on 2017/3/1.
 */
@Configuration
@Profile("mysql")
@PropertySource("classpath:conf/db.properties")
public class MysqlDataSourceConfig implements RmdbsDataSourceConfig{
    @Autowired
    private Environment environment;

    @Override
    @Bean("mysqlDataSource")
    public DataSource createDataSource() {
        DruidDataSource ds = new DruidDataSource();
        ds.setMaxActive(8);
        ds.setDriverClassName(environment.getProperty("jdbc.driverClassName"));
        ds.setUrl(environment.getProperty("jdbc.url"));
        ds.setPassword(environment.getProperty("jdbc.password"));
        ds.setUsername(environment.getProperty("jdbc.username"));

        return ds;
    }
}
